package com.OA.controller;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.OA.entity.SignIn;
import com.OA.service.SignIn_CY_service;
import com.OA.util.Page;
import com.alibaba.fastjson.JSON;

/**
 * 出勤管理
 * @author thinkpad
 *
 */
@Controller
@RequestMapping("sign")
public class SignIn_CY_controller {

	@Autowired
	private SignIn_CY_service signService;
	
	@Autowired
	public static Map<String, Object> map = new HashMap<String, Object>();
	
	/**
	 * 加载该用户的出勤记录和组合条件搜索加载的出勤记录
	 * @param userId
	 * @param pageNo
	 * @param pageSize
	 * @param late
	 * @param before
	 * @param fromDate
	 * @param toDate
	 * @param resp
	 * @throws IOException
	 */
	@RequestMapping(value="loadSignIn.do")
	public void loadSignIn(int userId,int pageNo,int pageSize,
			String late,String before,String fromDate,String toDate,
			HttpServletResponse resp) throws IOException{
		map.put("userId", userId);
		map.put("pageNo", pageNo);
		map.put("pageSize", pageSize);
		map.put("late", late);
		map.put("before", before);
		map.put("fromDate", fromDate);
		map.put("toDate",toDate);
		try
			{ 
			System.out.println("本机的IP = " + InetAddress.getLocalHost().getHostAddress());
			} catch (UnknownHostException e)
			{ 
			e.printStackTrace();
			}
		Page<SignIn> page = signService.loadSignIn(map);
		for(SignIn s :page.getRows()){
			System.out.println(s.getOnDutyTime());
		}
		resp.getWriter().write(JSON.toJSONString(page));
		resp.getWriter().flush();
		resp.getWriter().close();
		
	}
	 
}
